/*
 * Copyright 2015 William Wang.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package wxk.Bonus.bean;

import java.lang.reflect.Field;
import java.util.ArrayList;
import wxk.Bonus.utils.BonusLogger;

/**
 * Jan 20, 20152:06:36 PM
 * @author William Wang
 */
public class ChinaDoubleBallBean implements GeneralBean{
 private  static final long serialVersionUID = -4759527637665705469L;
 private ArrayList<Integer> balls=new ArrayList<Integer>();
 private String term;
 private String date;
 private int red1;
 private int red2;
 private int red3;
 private int red4;
 private int red5;
 private int red6;
 private int red7;
 private int red8;
 private int red9;
 private int red10;
 private int red11;
 private int red12;
 private int red13;
 private int red14;
 private int red15;
 private int red16;
 private int red17;
 private int red18;
 private int red19;
 private int red20;
 private int red21;
 private int red22;
 private int red23;
 private int red24;
 private int red25;
 private int red26;
 private int red27;
 private int red28;
 private int red29;
 private int red30;
 private int red31;
 private int red32;
 private int red33;
 private int blue;
 private boolean isnext=false;//is next term data

    public boolean isIsnext() {
        return isnext;
    }

    public void setIsnext(boolean isnext) {
        this.isnext = isnext;
    }
 public ChinaDoubleBallBean(){};
 public ChinaDoubleBallBean(String term,String date,int r1,
         int r2,int r3,int r4,int r5,int r6,int bl)
 {

  this.term = term;
  this.date = date;
  setRed(r1);
  setRed(r2);
  setRed(r3);
  setRed(r4);
  setRed(r5);
  setRed(r6);
  this.blue =  bl;
 }
    public String getTerm() {
        return term;
    }

    public ChinaDoubleBallBean setTerm(String term) {
        this.term = term;
        return this;
    }

    public String getDate() {
        return date;
    }

    public ChinaDoubleBallBean setDate(String date) {
        this.date = date;
        return this;
    }
 
    //check this term include some value
    public boolean contains(String... value)
 {
   boolean result=true;
   int t=-1;
   for(String v:value)
   {
    t=Integer.valueOf(v);
   if(!balls.contains(t))return false;    
   }
   return result;
 }
    public ChinaDoubleBallBean setRed(int value)
    {
     try
     {
    String fieldname=String.format("red%d",value);  
//    BonusLogger.getInstance().log("setRed:"+fieldname);
    Field field=this.getClass().getDeclaredField(fieldname);
    field.setAccessible(true);
    field.setInt(this, value);        
     balls.add(value);
     }catch(Exception e)
     {
         System.out.println(e.getMessage());
     }
     return this;   
    }
    public String getBlue() {
        return String.format("%02d",blue);
    }

    public ChinaDoubleBallBean setBlue(int blue) {
        this.blue = blue;
        return this;
    }

    @Override
    public String toString() {
        return "ChinaDoubleBallBean{" + "term=" + term + ", date=" + date + ", red1=" + red1 + ", red2=" + red2 + ", red3=" + red3 + ", red4=" + red4 + ", red5=" + red5 + ", red6=" + red6 + ", red7=" + red7 + ", red8=" + red8 + ", red9=" + red9 + ", red10=" + red10 + ", red11=" + red11 + ", red12=" + red12 + ", red13=" + red13 + ", red14=" + red14 + ", red15=" + red15 + ", red16=" + red16 + ", red17=" + red17 + ", red18=" + red18 + ", red19=" + red19 + ", red20=" + red20 + ", red21=" + red21 + ", red22=" + red22 + ", red23=" + red23 + ", red24=" + red24 + ", red25=" + red25 + ", red26=" + red26 + ", red27=" + red27 + ", red28=" + red28 + ", red29=" + red29 + ", red30=" + red30 + ", red31=" + red31 + ", red32=" + red32 + ", red33=" + red33 + ", blue=" + blue + '}';
    }
    
  private String getRed(int num)
  {
    String value="";  
       try
     {
    String fieldname=String.format("red%d",num);  
    Field field=this.getClass().getDeclaredField(fieldname);
    field.setAccessible(true);
    value=String.format("%02d", field.getInt(this));
     }catch(Exception e)
     {
         e.printStackTrace();
     }    
   return value;    
  }
  
    public String getRed1() {
        return getRed(1);
    }

    public String getRed2() {
        return getRed(2);
    }

    public String getRed3() {
       return getRed(3);
    }

    public String getRed4() {
        return getRed(4);
    }

    public String getRed5() {
        return getRed(5);
    }

    public String getRed6() {
        return getRed(6);
    }

    public String getRed7() {
        return getRed(7);
    }

   public String getRed8() {
        return getRed(8);
    }

    public String getRed9() {
        return getRed(9);
    }

   public String getRed10() {
        return getRed(10);
    }

    public String getRed11() {
        return getRed(11);
    }

    public String getRed12() {
        return getRed(12);
    }

    public String getRed13() {
        return getRed(13);
    }

    public String getRed14() {
        return getRed(14);
    }

    public String getRed15() {
        return getRed(15);
    }

    public String getRed16() {
        return getRed(16);
    }

    public String getRed17() {
        return getRed(17);
    }

    public String getRed18() {
        return getRed(18);
    }

    public String getRed19() {
        return getRed(19);
    }

    public String getRed20() {
        return getRed(20);
    }

    public String getRed21() {
       return getRed(21);
    }

    public String getRed22() {
        return getRed(22);
    }

   public String getRed23() {
        return getRed(23);
    }

    public String getRed24() {
        return getRed(24);
    }

   public String getRed25() {
        return getRed(25);
    }

   public String getRed26() {
        return getRed(26);
    }

    public String getRed27() {
        return getRed(27);
    }

    public String getRed28() {
        return getRed(28);
    }

    public String getRed29() {
        return getRed(29);
    }

    public String getRed30() {
        return getRed(30);
    }

    public String getRed31() {
        return getRed(31);
    }

    public String getRed32() {
        return getRed(32);
    }

    public String getRed33() {
        return getRed(33);
    }


 
}
